Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WebAssembly version libraries for unit testing #16264

Merged
merged 3 commits into from
Sep 19, 2023

Conversation

shrinktofit
Copy link
Contributor

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@github-actions
Copy link

Interface Check Report

This pull request does not change any public interfaces !

Comment on lines +29 to +53
export async function instantiateWasm (wasmUrl: string, importObject: WebAssembly.Imports): Promise<any> {
return fetchBuffer(wasmUrl).then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, importObject));
}

export async function fetchBuffer (binaryUrl: string): Promise<ArrayBuffer> {
const relativePathToExternal = /^external:(.*)/.exec(binaryUrl)?.[1];
if (relativePathToExternal) {
const externalHome = join(__dirname, '..', '..', 'native', 'external');
const path = join(externalHome, relativePathToExternal);
try {
const content = readFileSync(path);
return content.buffer;
} catch (err) {
throw new Error(`Unable to fetch buffer from ${binaryUrl}`, { cause: error });
}
}

throw new Error(`Don't know how to fetch buffer at url ${binaryUrl}`);
}

export async function ensureWasmModuleReady() {
return Promise.resolve();
}

checkPalIntegrity<typeof import('@pal/wasm')>(withImpl<typeof import('./pal-wasm-testing')>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add this file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes it possible to use wasm in unit test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't actually mock pal/wasm module to the web implementation

@PPpro
Copy link
Contributor

PPpro commented Sep 18, 2023

@lealzhan lealzhan merged commit 5682bbf into cocos:v3.8.2 Sep 19, 2023
10 checks passed
@shrinktofit shrinktofit deleted the UnitTestWasm branch September 20, 2023 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants